//
//  TestListPageVC.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/9/27.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import Foundation
import RxSwift
import CooperSwift

class TestListPageVC: UIViewController, TableEnableProtocol, Refreshable {
    let vm = ViewModelFactory.tableVM(TestListPageVM.self)
    let disposeBag = DisposeBag()
    override func viewDidLoad() {
        super.viewDidLoad()
        rx.updateRefresh(vm, scrollview: tableView, bag: disposeBag, refreshConfig: .header)
        configAll(vm, disposeBag: disposeBag)
//        rx.updateEmptyDataSet(tableView)
    }
}

class TestListPageVM: NSObject, TableViewModelProtocol, RefreshControllable {
    func configDown() {
        toState(.loading)
        PublicMethod.delay(3) {
            self.toState(.failure)
        }
//        refresh()
    }
    func refresh() {
        debugPrint("⭐️⭐️⭐️⭐️⭐️refresh⭐️⭐️⭐️⭐️⭐️")
        PublicMethod.delay(3) {
            self.toState(.noData)
            self.rx.refreshStatus.onNext(.endHeaderRefresh)
            if Int.random() % 2 == 0 {
                self.rx.refreshStatus.onNext(.showFooter)
            }else {
                self.rx.refreshStatus.onNext(.hiddenFooter)
            }
        }
    }
    func pullUp() {
        debugPrint("⭐️⭐️⭐️⭐️⭐️pullUp⭐️⭐️⭐️⭐️⭐️")
        PublicMethod.delay(1) {
            self.toState(.noData)
            self.rx.refreshStatus.onNext(.endFooterRefresh)
        }
    }
}
